package com.xxgc.ssm.resolver;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;

/**
 * 自定义登录异常处理类
 * @program: spring-study
 * @Email：2119196781@qq.com
 * @description
 * @author: 小唐唐
 * @create: 2021-11-23 09:37
 **/
//@Component
public class LoginExceptionResolver implements HandlerExceptionResolver {
    /**
     * 参数Exception
     * @param httpServletRequest
     * @param httpServletResponse
     * @param o
     * @param e
     * @return ModelAndView
     */
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        ModelAndView modelAndView = new ModelAndView();
        if(e instanceof FileNotFoundException){
            modelAndView.addObject("msg","文件异常");
            modelAndView.addObject("code","Foo_sdsa");
            modelAndView.setViewName("file_error");
            System.out.println("状态码："+httpServletResponse.getStatus());
        }else {
            modelAndView.setViewName("error");
        }
        return modelAndView;
    }
}